/*
*    Phantom v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
// FunctionDecl.h: interface for the CFunctionDecl class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_FUNCTIONDECL_H__81B08D09_B745_446F_A51C_DEA54D8F2A2E__INCLUDED_)
#define AFX_FUNCTIONDECL_H__81B08D09_B745_446F_A51C_DEA54D8F2A2E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "ssi_defines.h"
#include "ssi_tnode.h"
#include "ssi_string.h"	// Added by ClassView

#include "ssi_ghostclass.h"
#include "ssi_scriptline.h"	// Added by ClassView

#include "ssi_componentparser.h"

class CData;
class CEngine;
//class GhostClass;

#define ENGINE_FUNCTION_TYPE    1
#define GLOBAL_FUNCTION_TYPE    2
#define USER_FUNCTION_TYPE      4
#define CDATA_FUNCTION_TYPE     8

#define RETURN_ARRAY            8
#define RETURN_CLASS            16

//typedef void* (*FunctionDeclPtr) ( SSI_BYTE* );
//typedef void* (GhostClass::*ClassFunctionDeclPtr)(void);

typedef void* (*FunctionDeclPtr) ( ... );
typedef void* (GhostClass::*ClassFunctionDeclPtr)( ... );

class SSI_FunctionAPI;
typedef void* (CData::*DataProcessingFunctionPtr)(SSI_FunctionAPI&);
typedef void* (*ProcessingFunctionPtr)(SSI_FunctionAPI&);
typedef void* (GhostClass::*ClassProcessingFunctionPtr)(SSI_FunctionAPI&);

typedef struct{
  String Name;
  SSI_INT64 Type;
}FunctionParamTypeT;

class SSI_SCRIPTDLL_API CFunctionDecl  
{
public:
	ScriptTree ScriptLines;
	SSI_INT64 Flags;
	//void SetFunctionDecl(ClassFunctionDeclPtr aFunc, void* anObject);
	//void SetFunctionDecl(FunctionDeclPtr aFunc);
	
	friend class CEngine;
	friend class CData;
  void Clear();

  CFunctionDecl(CFunctionDecl &Other);
	SSI_INT64 ReturnType;
	String Name;
	String FileName;
  
  // Name is only used for user-defined functions
	SSI_INT64 addType(SSI_INT64 Type, String Name = "");

  virtual bool operator<(const CFunctionDecl& Other) const;
  virtual CFunctionDecl& operator= (CFunctionDecl& Other);
  SSI_INT64 getNumParams();
  SSI_INT64 getParamType(SSI_INT64 Index);
  String getParamName(SSI_INT64 Index);

	CFunctionDecl();
	virtual ~CFunctionDecl();

  SSI_BOOL operator ==(CFunctionDecl& Other);

	void SetProcessor(ProcessingFunctionPtr newProc);
	void SetProcessor(GhostClass* ProcClass);
	void SetProcessor(CData* ProcData);
private:
	GhostClass* objectPtr;
	CData* dataPtr;
  //typedef TNodeTree<SSI_CHAR> TypeTree;
	//typedef TNode<SSI_CHAR> TypeNode;

  typedef TNodeTree<FunctionParamTypeT> TypeTree;
  typedef TNode<FunctionParamTypeT> TypeNode;

	// These will be removed
  // FunctionDeclPtr theGlobalFunction;
	// ClassFunctionDeclPtr theClassFunction;
	
	ProcessingFunctionPtr theProcessor;
	// ClassProcessingFunctionPtr theClassProcessor;
	
	SSI_BYTE FunctionType;

  TypeTree Types;
  SSI_INT64 numParams;

  public:
	SSI_BOOL bIsDefined;
	SSI_CHAR Access;
	String Package;

};


typedef TNodeTree<CFunctionDecl> FuncTree;
typedef TNode<CFunctionDecl> FuncNode;


#endif // !defined(AFX_FUNCTIONDECL_H__81B08D09_B745_446F_A51C_DEA54D8F2A2E__INCLUDED_)



